﻿using LevelEditor.Document;
using LevelEditor.Forms;

namespace LevelEditor.View
{
    public class DoUndoRemoveLayer : DoUndoNothing
    {
        #region Fields

        int Index;

        Layer UndoLayer;

        #endregion

        #region Constructors

        public DoUndoRemoveLayer(MainForm form, int index):base(form)
        {
            Index = index;
            UndoLayer = form.Level.Layers[Index];
        }

        #endregion

        #region Methods

        public override bool Do()
        {
            MainForm.Level.Layers.RemoveAt(Index);
            MainForm.LayerViewControl.Views.RemoveAt(Index);
            if (MainForm.CurrentLayer > MainForm.Level.Layers.Count - 1)
                MainForm.CurrentLayer = MainForm.Level.Layers.Count - 1;
            MainForm.RefreshControlData();
            return true;
        }

        public override void Undo()
        {
            Layer uLayer = new Layer(UndoLayer);
            MainForm.Level.Layers.Insert(Index, uLayer);
            MainForm.LayerViewControl.Views.Insert(Index, new LayerView(uLayer));
            MainForm.CurrentLayer = Index;
            MainForm.RefreshControlData();
        }

        public override string ToString()
        {
            return "Remove layer " + Index.ToString();
        }

        #endregion
    }
}
